﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SOEN344_Term_Assignment.Models;

namespace SOEN344_Term_Assignment
{
    public partial class _BookingsView : System.Web.UI.Page
    {
        EventSchedulerDataContext _proxy;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (_proxy == null)
            {
                _proxy = new EventSchedulerDataContext();
            }


            if (!IsPostBack)
            {

                //List<Booking> bookingssFromDB = _proxy.Bookings.ToList();

                BookingsGridView.DataSource = _proxy.Bookings;
                BookingsGridView.DataBind();

                if (BookingsGridView.Rows.Count > 1)
                {
                    BookingsGridView.Visible = true;
                }
                else
                {
                    BookingsGridView.Visible = false;
                }
                BookingsGridView.HeaderRow.Cells[4].Text = "Event";

                foreach (GridViewRow row in BookingsGridView.Rows)
                {
                    
                        int eventID = Convert.ToInt32(row.Cells[4].Text);
                        var currentEvent = _proxy.Events.Where(x => x.ID == eventID).FirstOrDefault();
                        row.Cells[4].Text = currentEvent.Title;
                    
                }

            }
            
        }

        protected void BookingsGridView_DataBound(object sender, EventArgs e)
        {
        }

     
    }
}
